import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx' //tsx插件引入
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
import ViteRestart from 'vite-plugin-restart'
import ElementPlus from 'unplugin-element-plus/vite'
import SvgIconsPlugin from './svg-icon'
import eslintPlugin from './eslintPlugin'
import { compressImgPlugin } from './compressImg'
import { autoImport, comImport } from './automatic_import'
import { ele_plus_dev } from './element-plus-dev'
import { compressGzipPlugin } from './copmressGzip'
import { visualizer } from 'rollup-plugin-visualizer'
import { PluginOption } from 'vite'
export default function createVitePlugins(
  viteEnv: Record<string, string>,
  isBuild = false
): PluginOption[] {
  const vitePlugins: PluginOption[] = [
    vue(),
    vueJsx(),
    VueSetupExtend(),
    ViteRestart(),
    ElementPlus({
      useSource: true
    })
  ]
  vitePlugins.push(SvgIconsPlugin(isBuild))
  vitePlugins.push(eslintPlugin())
  vitePlugins.push(autoImport())
  vitePlugins.push(comImport(isBuild))
  vitePlugins.push(ele_plus_dev(viteEnv))
  isBuild && vitePlugins.push(compressImgPlugin())
  isBuild && vitePlugins.push(compressGzipPlugin())
  vitePlugins.push(visualizer() as PluginOption)
  return vitePlugins
}
